﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Manage_studentList : System.Web.UI.Page
{
    BLL.StudentBll sb = new BLL.StudentBll();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
            ShowPageFooter();
        }
    }

    private void BindData()
    {
        DataTable table = sb.GetAllStudent();
        grd_Student.DataSource = table;
        grd_Student.DataBind();

        

        //显示总条数
        Label lblCount = (Label)grd_Student.BottomPagerRow.FindControl("lbl_Count");
        lblCount.Text = table.Rows.Count.ToString();
    }

    private void ShowPageFooter()
    {
        //给显示分页TextBox赋值
        TextBox txtPageIndex = (TextBox)grd_Student.BottomPagerRow.FindControl("txt_PageIndex");
        txtPageIndex.Text = (grd_Student.PageIndex + 1).ToString();
    }
    protected void grd_Student_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grd_Student.PageIndex = e.NewPageIndex;

        BindData();
        ShowPageFooter();
    }
    protected void grd_Student_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Go")
        {
            try
            {
                TextBox txtPageIndex = (TextBox)grd_Student.BottomPagerRow.FindControl("txt_PageIndex");
                int index = Int32.Parse(txtPageIndex.Text);
                GridViewPageEventArgs ea = new GridViewPageEventArgs(index - 1);
                grd_Student_PageIndexChanging(null, ea);
            }
            catch
            {

            }
        }
    }
}
